local guxuan = fk.CreateSkill {
  name = "investiture__guxuan",
  tags = { Skill.Lord },
}

Fk:loadTranslationTable {
  ["investiture__guxuan"] = "孤悬",
  [":investiture__guxuan"] = "主公技，你受到伤害时，若你的手牌均明置或均暗置，你摸一张牌并令此伤害+1；商势力角色触发“溺业”使用【酒】改为暗置你的黑色手牌。",

  ["$investiture__guxuan1"] = "孤自知命端缜重，宸极寡伴，此乃天数也。",
  ["$investiture__guxuan2"] = "尔等食商之禄，则为孤之牛犬，安敢妄反！",
}

local DIY = require "packages/diy_utility/diy_utility"
local TuntianUtil = require "packages/tuntian_studio/utility"

guxuan:addEffect(fk.DamageInflicted, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill("investiture__guxuan") and player == target and not data.prevented then
      return table.every(player:getCardIds("h"), function(c) return TuntianUtil.isShown(c) end)
          or table.every(player:getCardIds("h"), function(c) return not TuntianUtil.isShown(c) end)
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:notifySkillInvoked(player, guxuan.name, "negative")
    player:broadcastSkillInvoke(guxuan.name, 1)
    player:drawCards(1, guxuan.name)
    data.damage = data.damage + 1
  end
})

guxuan:addEffect(fk.BeforeCardsMove, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill("investiture__guxuan") then
      local use = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
      if use and use.data.card and use.data.card.trueName == "analeptic" and use.data.card.skillName:find("investiture__niye") and use.data.from.kingdom == "shang" then
        event:setCostData(self, use.data.card:getEffectiveId())
        return true
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:notifySkillInvoked(player, guxuan.name, "support")
    player:broadcastSkillInvoke(guxuan.name, 2)
    local id = event:getCostData(self) ---@type number
    for _, move in ipairs(data) do
      for _, info in ipairs(move.moveInfo) do
        if info.cardId == id then
          move.moveInfo = {}
          break
        end
      end
    end
    DIY.hideCards(player, { id })
  end,
})

return guxuan
